<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增器材型号')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-mode-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">器材类型：</label>
                <div class="col-sm-8">
                    <input name="typeName" id="typeName" onclick="gotoSelectValidDeviceTypeTree()" class="form-control" type="text" autocomplete="off" required>
                    <input name="typeId" id="typeId" class="form-control" type="hidden" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">器材型号：</label>
                <div class="col-sm-8">
                    <input name="modeName" id="modeName" class="form-control" type="text" autocomplete="off" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">单位：</label>
                <div class="col-sm-8">
                    <select name="unit" class="form-control" th:with="type=${@dict.getType('sys_unit')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">顺序：</label>
                <div class="col-sm-8">
                    <input name="sequence" class="form-control" type="number" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/mode"
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#form-mode-add").validate({
            focusCleanup: true,
            rules: {
                typeId: "required",
                modeName: {
                    required: true,
                    remote:  {
                        url: "/system/mode/checkModeName",     //后台处理程序
                        type: "post",               //数据发送方式
                        dataType: "json",           //接受数据格式
                        data: {                     //要传递的数据
                            modeName: function () {
                                return $("#modeName").val();
                            }
                        }
        }
                }
            },
            messages: {
                typeId: icon + "请选择器材类型",
                modeName: {
                    required: icon + "请输入器材型号名称",
                    remote: icon + "该器材型号名称已经存在"
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-mode-add').serialize());
            }
        }

        /* 器材管理-选择器材类型名称 */
        function gotoSelectValidDeviceTypeTree() {
            var url = ctx + "system/type/gotoDeptTree";
            var options = {
                title: '选择器材类型',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#typeId").val(body.find('#deviceTypeId').val());
            $("#typeName").val(body.find('#deviceTypeName').val());
            layer.close(index);
        }
    </script>
</body>
</html>